package cn.zwxky.android.staff.Jurisdiction.Furlough;

import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.URLString;


/**
 * Created by Administrator on 2017/3/30 0030.
 */
@ContentView(R.layout.aty_manage_leave)
public class ManageLeaveActivity extends LsfbActivity {


    /**
     * 点击刷新布局控件
     */
    @ViewInject(R.id.swiplayout)
    private SwipeRefreshLayout swipeRefreshLayout;

    /**
     * list列表
     */
    @ViewInject(R.id.dish_list)
    private RecyclerView dish_list;

    /**
     * RecyclerView的布局管理器
     */
    private RecyclerView.LayoutManager mlayoutManager;

    private List<ManageLeaveBean.ListBean> mList;

    private ManageLeaveAdapter adapter;

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "请假审批");

        mList=new ArrayList<>();
        adapter=new ManageLeaveAdapter(this,mList,R.layout.item_leave);
        mlayoutManager = new LinearLayoutManager(this);//布局模式为listview方式
        dish_list.setLayoutManager(mlayoutManager);
        dish_list.setAdapter(adapter);

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getData();
            }
        });

    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    public void getData(){
        HashMap<String, String> hashMap = new HashMap<String, String>();
           hashMap.put("uid", Config.getUserId());
        new BaseInternet().getData_Get(URLString.LEAVE_OP, hashMap, ManageLeaveBean.class, new ManageLeaveEvent<ManageLeaveBean>(), true,true);
    }

    @EventAnnotation
    public void ManageLeaveEvent(ManageLeaveEvent<ManageLeaveBean> event){
        swipeRefreshLayout.setRefreshing(false);
        switch (event.getCode()){
            case 200:
                mList.clear();
                mList.addAll(event.getData().getList());
                adapter.notifyDataSetChanged();
                break;
            default:
                mList.clear();
                adapter.notifyDataSetChanged();
                SN.SnackShow(dish_list,event.getMsg());
                break;
        }
    }

    @EventAnnotation
    public void ManageLeaveClickEvent(ManageLeaveClickEvent event){
        startActivity(new Intent(this, ManageLeaveDetailsActivity.class).putExtra("id",event.getData()));
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }


}
